﻿<Window x:Class="SPListsCaller.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:w="clr-namespace:SPListsCaller.Tools"
        xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:xctkconv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters;assembly=Xceed.Wpf.Toolkit"
        Title="Lists.asmx - GetListItems" Height="580" Width="800">

    <Window.Resources>
        <xctkconv:VisibilityToBoolConverter x:Key="VisibilityToBoolConverter" Inverted="True"/>
    </Window.Resources>

    <Grid>

        <!--InnerGrid-->
        <Grid>



            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>

            <!--
            *********************************************************************************************
            *** Left side
            *********************************************************************************************
         -->
            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="90"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="180" />
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="100"/>
                </Grid.RowDefinitions>

                <!--
        **********************************************************************
        Credentiels
        **********************************************************************
        -->
                <TextBlock Text="Credentials" Grid.Row="0" FontSize="30" Foreground="DarkGray" Padding="15,0,0,0" />
                <!--<Grid Margin="0,0,0,10" Grid.Row="1" DataContext="{Binding Path=Credential}">-->
                <Grid Margin="0,0,0,10" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Text="Domain" Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=Domain, Mode=TwoWay}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                    <TextBlock Text="Login" Grid.Row="1" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=Login, Mode=TwoWay}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                    <TextBlock Text="Password" Grid.Row="2" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <!--<TextBox Text="{Binding Path=Password, Mode=TwoWay}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>-->
                    <PasswordBox w:PasswordHelper.Attach="True" w:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}"  Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                </Grid>

                <!--
        **********************************************************************
        Parametres
        **********************************************************************
        -->
                <TextBlock Text="Parameters" Grid.Row="2" FontSize="30" Foreground="DarkGray" Padding="15,0,0,0" />
                <Grid Margin="0,0,0,10" Grid.Row="3" DataContext="{Binding Path=QueryParams}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="20" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock Text="ListName" Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=ListName, Mode=TwoWay}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                    <TextBlock Text="ViewName" Grid.Row="1" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=ViewName, Mode=TwoWay}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                    <TextBlock Text="Query" Grid.Row="2" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=Query, Mode=TwoWay}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>
                    <Button Content=">" Click="OnEditXmlProperty" Tag="Query" Grid.Row="2" Grid.Column="2" />

                    <TextBlock Text="ViewFields" Grid.Row="3" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=ViewFields, Mode=TwoWay}" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>
                    <Button Content=">" Click="OnEditXmlProperty" Tag="ViewFields" Grid.Row="3" Grid.Column="2" />

                    <TextBlock Text="QueryOptions" Grid.Row="4" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=QueryOptions, Mode=TwoWay}" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>
                    <Button Content=">" Click="OnEditXmlProperty" Tag="QueryOptions" Grid.Row="4" Grid.Column="2" />

                    <TextBlock Text="RowLimit" Grid.Row="5" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=RowLimit, Mode=TwoWay}" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>
                </Grid>

                <!--
        **********************************************************************
        Actions
        **********************************************************************
        -->
                <TextBlock Text="Actions" Grid.Row="4" FontSize="30" Foreground="DarkGray" Padding="15,0,0,0" />

                <Grid Margin="0,0,0,10" Grid.Row="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="Url" Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" />
                    <TextBox Text="{Binding Path=Url}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="2"/>

                </Grid>

                <Grid Grid.Row="6">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <Button Content="Call By Query ..." Margin="5" Grid.ColumnSpan="2" Click="CallByQuery_Click" />
                    <Button Content="Save config" Margin="5" Grid.Row="1" Grid.Column="0" Click="SaveConfig_Click" />
                    <Button Content="Load config" Margin="5" Grid.Row="1" Grid.Column="1" Click="LoadConfig_Click" />
                    <Button Content="Export query" Margin="5" Grid.Row="2" Grid.Column="0" Click="ExportQuery_Click" />
                    <Button Content="Import query" Margin="5" Grid.Row="2" Grid.Column="1" Click="ImportQuery_Click" />
                </Grid>

            </Grid>

            <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" Background="Gray" />

            <!--
            *********************************************************************************************
            *** Right side
            *********************************************************************************************
        -->
            <Grid  Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>

                <avalonEdit:TextEditor Grid.Row="0" Name="textEditor" SyntaxHighlighting="XML" FontFamily="Consolas" FontSize="10pt"/>

                <Grid Grid.Row="1" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <ListBox Grid.Column="0" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=CurrentFieldNames}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" Margin="2" Background="LightGray"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" Background="Gray" />
                    <DataGrid Name="dgResult" DataContext="{Binding Path=CurrentDataTable}" Grid.Column="2" 
                          AutoGenerateColumns="True" CanUserResizeRows="True" CanUserResizeColumns="True" RowHeaderWidth="10" RowHeight="25" />

                </Grid>

                <Grid Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition Width="200"/>
                    </Grid.ColumnDefinitions>


                    <TextBlock Text="{Binding Path=TableItemsCount}" FontSize="20" Foreground="DarkGray" Padding="15,0,15,0" HorizontalAlignment="Right" />
                    <TextBlock Text="items" FontSize="20" Foreground="DarkGray" Padding="15,0,0,0" Grid.Column="1" />
                    <Button Content="Save xml" Grid.Column="2" Width="150" HorizontalAlignment="Left" Margin="20,0,0,0" Click="SaveXml_Click" />

                </Grid>

            </Grid>

        </Grid>

        <xctk:WindowContainer>
            <xctk:ChildWindow Name="paramEditorWindow"
                    Width="500"
                    Height="400"
                    WindowState="Closed"
                    WindowStartupLocation="Center"
                    Caption="lmondeil">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="30"/>
                    </Grid.RowDefinitions>

                    <avalonEdit:TextEditor Grid.Row="0" Name="paramEditor" SyntaxHighlighting="XML" FontFamily="Consolas" FontSize="10pt" />

                    <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                        <Button Content="Valider" Click="OnValidatePopup" Margin="2" Width="100"/>
                        <Button Content="Annuler" Click="OnCancelPopup" Margin="2" Width="100"/>
                    </StackPanel>
                </Grid>

            </xctk:ChildWindow>
        </xctk:WindowContainer>

    </Grid>
</Window>
